Repository navigation
v0.9.1: Cellpose weights download on first use, pinned and checked; one torch warning hidden (#574 items 3 and 5) - #577
Draft
guijacquemet wants to merge 2 commits into
Draft
guijacquemet wants to merge 2 commits into
guijacquemet wants to merge 2 commits into
Conversation
… torch warning (#574) Item 3 (owner decision, 26 November 2026): choosing the model and pressing Preview or Segment (or Load the model) is the consent to download its weights. The weights-download and DINOv3 ticks are removed from the model form. The brick downloads only the chosen model's file from the Hugging Face repository at a pinned commit, keeps it only with its pinned size and SHA-256 (a cached copy is checked too), and hands Cellpose the absolute path. A failed or blocked download is a refusal naming the model and the URL; no other model is used. The notebook shows a "Downloading <model> weights..." line with progress. DINOv3 is installed at its pinned commit on a DINOv3 model's first load when none is installed; another commit is refused, not replaced. The record adds weights_repository, weights_revision, dinov3_source and dinov3_installed. Item 5: evaluate runs model.eval inside sparse_warning_hidden(), which filters only torch's "Sparse invariant checks are implicitly disabled" UserWarning from the torch or cellpose modules, in catch_warnings. normalization, eval_arguments and inference_parameters move to segmentation_cellpose_eval (re-exported) for the 600-line rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
…rors (review of #577) - The weights file's identity (device, inode, size, mtime_ns) taken when it is hashed must be unchanged right before Cellpose opens it and after it loaded it (also for a model file of one's own), else the load is refused: a file gone in between would make Cellpose fetch a model from its moving branch with TLS off while the record carried the pinned hash. - A local write error (a full disk) is a write refusal naming the folder, not a network one; a failed rename is a SegmentationError naming the target; the download is fsynced before the rename. - Tests: the identity checks (removed, replaced, gone before the load, own file), the sparse filter put back when Cellpose raises, the full disk, the failed rename and fsync before rename. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a
guijacquemet
pushed a commit
that referenced
this pull request
Nov 26, 2026
…l-running line (#574 item 4) #576 shipped in the v0.9.0 tag through the release branch but was never merged into main, so v0.9.1 would have lost it. Merged here; conflicts with #577's load signature resolved (clear_preview kept, no download ticks). #574 item 4 on top: while the model segments the preview image the line says "Running <model> on <image>…" for each model in turn, with a ticking time (notebook_progress.Wait), and the batch's progress line names the model ("Running <model> · n of N · <image>"). Tests in test_notebook_cellpose_preview and test_notebook_cellpose_preview_stale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VbytvF3Gsa85ix8Ne2yMDW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements items 3 and 5 of #574 for v0.9.1. This is a draft. Do not merge yet.
Summary (by module)
segmentation_cellpose_weights(new). Owner decision of 26 November 2026: choosing the model and pressing Preview or Segment (or Load the model in the Cellpose notebook) is the consent to download that model's weights.fetch_weightsdownloads only the chosen model's file. The source ismouseland/cellpose-samat a pinned commit,WEIGHTS_REVISION=7c61431b5fbb…. Cellpose itself uses the movingmainbranch and turns TLS verification off; this download keeps verification on..partfile next to the target. They replace the target only if they have the pinned size and SHA-256 (PINNED_WEIGHTS, the LFS hashes that Hugging Face lists at that commit).segmentation_cellpose_model.load_model(model, device, *, progress=None): theallow_downloadargument is removed. Cellpose now always gets the absolute path of the checked file, so it never downloads anything and cannot substitute another file.LoadedModelgainsrepository,revisionanddinov3_installed.dinov3_vitl16/dinov3_vitb16(pretrained=False). All of their weights are in the Cellpose file, so DINOv3 downloads no weights of its own.ensure_dinov3installs DINOv3 at the pinned commit with--no-deps. This happens on the first load of such a model, only when no DINOv3 is installed, and before Cellpose is imported. A DINOv3 already installed at another or unknown commit is refused, with the command to run; it is not replaced.cellpose.vit. Cellpose 4.2.1.1 definesCPDINOwhether or not DINOv3 imports, so the oldhasattr(models, "CPDINO")check could never fail. If Cellpose was already imported, the load asks for a runtime restart.notebook_cellpose_fields,_form,notebook_cellpose,notebook_cellpose_download).DownloadLineshows a "Downloading weights…" line while the weights download. It gives the MB received of the total, a bar and the elapsed time, then "done in m:ss" or "stopped after…". The same line shows "Installing DINOv3…" when DINOv3 is installed.tqdmbar is removed, because Cellpose no longer downloads.segmentation_cellpose.evaluaterunsmodel.evalinsidesparse_warning_hidden().warnings.catch_warnings()with onefilterwarnings("ignore", message=re.escape("Sparse invariant checks are implicitly disabled"), category=UserWarning, module=r"(cellpose|torch)(\.|$)").name,file,sha256. For a built-in model the SHA-256 equals the pinned one.parameters:weights_source(the pinned URL,…/resolve/<revision>/<name>),weights_repository,weights_revisionandweights_downloaded. For a DINOv3 model, alsodinov3_commit,dinov3_sourceanddinov3_installed. Theweights_*source fields are null for a user's own model file.segmentation_cellpose_eval(new, moved code).normalization,eval_argumentsandinference_parametersmoved here, unchanged apart from the new fields, and are re-exported bysegmentation_cellpose. This keepssegmentation_cellpose.pyunder the 600-line code rule.Decisions
docs/plan.md§12, question 86, and indocs/contract.md.main.Notes for review
MorphoBricks_Preprocessing_Cellpose.ipynb:RELEASE_REFis untouched (pins move only in the release PR).preview(). Only the load card in_load_modelchanged.cellpose_install.py's docstring andINSTALL_TEXTinnotebook_preprocessing_cellpose.pystill mention DINOv3 as "a choice of the model step". I left both for the install-cell work.cellpose.dynamics, based on reading the source. The filter covers both thecellpose.*andtorch.*modules.load_modelno longer takesallow_download.CellposeWorkflow.loadandload_nucleitake(model, custom_model_file, device).notebook_cellpose_download.BAR_LABELandnotebook_barare removed.Tests
tests/test_segmentation_cellpose_weights.py. It covers:cellpose.dynamics,torchandtorch.sparse, while other modules, categories and messages still show, and the filters are restored after the call.tests/cellpose_stub.py), the notebook, form, stepper and both tests, and the DINOv3 install tests (first use, another commit refused, restart refusal).pytest -k cellpose: 433 passed, 7 skipped.python tools/check.pyon head7c6a4c9(ruff check, ruff format --check, pytest, code rules): 8834 passed, 32 skipped, exit 0.python tools/check.py --rulespasses.Review follow-up (
ae64ecc)mainwith TLS off) can no longer pass unnoticed.SegmentationErrornaming the target. The download is fsynced before the rename.pytest -k cellpose: 441 passed, 7 skipped. Ruff on the changed files andtools/check.py --rulespass. I did not re-run the full check, as the coordinator asked.Links #574.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a